package com.yanqu.road.server.logic.bag;

import com.yanqu.road.entity.bag.UseGoodsResult;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.enums.eMonopolyMarketResType;
import com.yanqu.road.entity.monopolymarket.office.log.MonopolyMarketUserPhysicalChangeLogData;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.monopolymarket.MonopolyMarketModule;
import com.yanqu.road.server.manger.MonopolyMarketCommonMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.server.manger.monopolymarket.MonopolyMarketMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigInteger;

/**
 * 增加榷场体力
 */
public class UseRecoverMonopolyMarketPhysical extends BaseUseGoods {

    public UseRecoverMonopolyMarketPhysical(GamePlayer player, GoodsInfo goodsInfo, long param) {
        super(player, goodsInfo, param);
    }
    @Override
    int checkUse(long count) {
        if(!MonopolyMarketMgr.canEnterSystem(player)){
            return GameErrorCode.E_SYSTEM_NO_OPEN;
        }
        if(!MonopolyMarketCommonMgr.isSystemOpen(MonopolyMarketMgr.group, eMonopolyMarketResType.RES_KING.getValue()) && !MonopolyMarketCommonMgr.isSystemOpen(MonopolyMarketMgr.group, eMonopolyMarketResType.RES_QUEEN.getValue())){
            return GameErrorCode.E_MONOPOLY_MARKET_RES_GRAB_SYSTEM_NO_OPEN_NO_USE_PROP;
        }
        return 0;
    }

    @Override
    UseGoodsResult executeUse(long count) {
        MonopolyMarketModule marketModule = player.getModule(MonopolyMarketModule.class);

        UseGoodsResult result = new UseGoodsResult();
        BigInteger min = goodsInfo.getParamList().get(0);
        int addValue = (int)(min.intValue() * count);
        int oldValue = marketModule.baseData.getPhysical();

        MonopolyMarketMgr.addPhysical(player, marketModule, addValue);
        player.getModule(MonopolyMarketModule.class).synRoleData();

        result.setReward(PropertyHelper.parseGoodsToString(GameConfig.MONOPOLYMARKET_GUANYIN_ID,BigInteger.valueOf(addValue)));
        LogMgr.addMonopolyMarketUserPhysicalChangeLogData(new MonopolyMarketUserPhysicalChangeLogData(player.getUserId(),marketModule.baseData.getOfficeCurPos(),marketModule.baseData.getOfficeLevel(),marketModule.baseData.getOfficeNo(),3,oldValue,marketModule.baseData.getPhysical(), DateHelper.getCurrentSecond()));

        return result;
    }
}
